/**********************************************************************
 *
 *  File Name      : HELLO.c
 *  Date / Time    :
 *  Author         : 
 *
 *  Copyright      : 
 *
 *  Description    :
 *
 *  Change History :
 *      Date        Name         Reason
 *
 **********************************************************************/
#include <svcenv.h>

int SVC_FUNC_HELLO(MYSQLC db, char *request, char *respond)
{
    char para_desc[200];
    PARA para;
    char sql[200];
    struct dbc_rset rset;
    char uuid[UUID_SIZE+1];
    char loginname[LOGINNAME_SIZE+1];
    char nickname[NICKNAME_SIZE+1];
    int login_times;
    int res;

    sprintf(para_desc,
            "uuid(string:3-%d)",
            UUID_SIZE);
    res=para_load(request, para_desc, &para);
    if(res)
    {
        if(res > 0)
            errlog("%s: (%.20s) no.%d para invalid",
                    __func__, request, res);
        else
            errlog("%s: para_load fail, res:%d",
                    __func__, res);
        RETURN_ERR_PARA;
    }
    para_copy_by_name(para, "uuid", uuid);
    trim_tail_space_notnull(uuid);
    para_free(para);

    sprintf(sql,
            "select loginname,nickname,login_times from memb_info "
            "where uuid='%s'",
            uuid);
    res=mysqlc_query_ex(db, sql, 1, &rset);
    if(res != MY_OK && res != MY_NO_DATA_FOUND)
    {
        errlog("%s: mysqlc_query fail, res:%d",
                __func__, res);
        RETURN_ERR_DB;
    }
    if(res == MY_NO_DATA_FOUND)
    {
        errlog("%s: mysqlc_query %s not found",
                __func__, uuid);
        para_put_item(respond, SOAR_ERR_OK);
    }
    else
    {
        dbc_col_export_char(&rset, 0, 0, loginname); 
        dbc_col_export_char(&rset, 0, 1, nickname); 
        login_times=dbc_col_export_int(&rset, 0, 2); 
        dbc_query_free(&rset);
        para_put_item(respond, SOAR_ERR_OK);
        para_put_item(respond, uuid);
        para_put_item(respond, loginname);
        para_put_item(respond, nickname);
        para_put_item_int(respond, login_times);
    }

    return(0);
}
